# Maintainer: Hoang Nguyen <folliekazetani@protonmail.com>
pkgname=virter
pkgver=0.27.0
pkgrel=0
pkgdesc="CLI tool for simple creation and cloning of libvirt virtual machines"
url="https://github.com/LINBIT/virter"
arch="all"
license="Apache-2.0"
depends="libvirt dnsmasq-utils"
makedepends="go"
subpackages="
	$pkgname-doc
	$pkgname-bash-completion
	$pkgname-fish-completion
	$pkgname-zsh-completion
	"
source="$pkgname-$pkgver.tar.gz::https://github.com/LINBIT/virter/archive/refs/tags/v$pkgver.tar.gz
	update-mockery.patch
	"

build() {
	local _goldflags="
	-X github.com/LINBIT/virter/cmd.version=v$pkgver
	-X github.com/LINBIT/virter/cmd.builddate=$(date -u "+%Y-%m-%dT%H:%M:%S%z" ${SOURCE_DATE_EPOCH:+-d @$SOURCE_DATE_EPOCH})
	-X github.com/LINBIT/virter/cmd.githash=AlpineLinux
	"
	go build -v -ldflags "$_goldflags"

	for shell in bash fish zsh; do
		./virter completion $shell > virter.$shell
	done
}

check() {
	# Create mock files with mockery
	go generate internal/virter/virter_test.go

	go test ./...
}

package() {
	install -Dm755 virter -t "$pkgdir"/usr/bin/

	install -Dm644 doc/*.md -t "$pkgdir"/usr/share/doc/"$pkgname"/
	cp -r examples "$pkgdir"/usr/share/doc/"$pkgname"/

	install -Dm644 virter.bash \
		"$pkgdir"/usr/share/bash-completion/completions/virter
	install -Dm644 virter.fish \
		"$pkgdir"/usr/share/fish/vendor_completions.d/virter.fish
	install -Dm644 virter.zsh \
		"$pkgdir"/usr/share/zsh/site-functions/_virter
}

sha512sums="
4f6edd24eaf84b7fc08efcf2155e5e82c111cda36c380fee01094ecf5e41897fcec76306ffdd2a2e160591faf1d0776c49f6f47340b6960346a882c08dd34fd0  virter-0.27.0.tar.gz
8e383f190f0f9489e328257cb974d50be9b1f2cf862f2454beb89866ebb79c4745a08850b964ad5da7bac0c39059fdc643fcc8ce58c6af7b1216112fbb50582b  update-mockery.patch
"
